package mulMan.domain;

import java.util.List;
import java.util.Observable;
import java.util.Observer;

import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;

public class PlaylistFactory implements Observer, ApplicationContextAware{
	
	private List<Playlist> listOfPlaylists;
	private Playlist playlist;
	private ApplicationContext applicationContext;
	
	public PlaylistFactory() {
	}
	
	public Playlist addPlaylistToListOfPlaylist() {
		playlist = (Playlist) applicationContext.getBean("playlistModel");
		playlist.addObserver(this);
		
		listOfPlaylists = (ListOfPlaylists) applicationContext.getBean("listOfPlaylists");
		
		return playlist;
	}

	public void update(Observable o, Object arg) {

		if (arg == "id") {
			listOfPlaylists.add(playlist);
			playlist.deleteObserver(this);
		}
	}

	public void setApplicationContext(ApplicationContext arg0)
			throws BeansException {
		this.applicationContext = arg0;
	}
}
